package one.bugu.android.demon.util;

/**
 * PackageName: one.bugu.android.demon.util
 * Content: 编解码工具类
 *
 * @author Administrator
 * @date 2018/12/4 14:49
 */
public class CodeUtils {
    /**
     * 单例对象
     */
    private static volatile CodeUtils singleton = null;

    private CodeUtils() {

    }

    /**
     * 获取单例对象
     *
     * @return 单例对象
     */
    public static CodeUtils getInstance() {
        if (singleton == null) {
            synchronized (CodeUtils.class) {
                if (singleton == null) {
                    singleton = new CodeUtils();
                }
            }
        }
        return singleton;
    }

    /**
     * 以UTF_8形式编码
     *
     * @param tarStr
     * @return
     */
    public String str2Utf8(String tarStr) {
        String result = tarStr;
        try {
            result = new String(tarStr.getBytes("UTF-8"), "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
